import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7, ()->{
            System.out.println("集齐7个发明家,召唤神龙");
        });

        for (int i = 0; i < 100000000; i++) {
            final int num = i;
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + "\t收集到第"+num+"个发明家");
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();


             
        }

    }
}
